from flask import Flask,request,json,jsonify,render_template,redirect,url_for
from . import user,common

# 后台首页
def main():
    # 获取cookie
    uid = request.cookies.get('uid')
    token = request.cookies.get('token')
    if uid and token:
        is_login = common.certify_user(uid,token)
        if is_login:
            return render_template('admin/index.html')
        else:
            return redirect(url_for('login'))
    else:
        return redirect(url_for('login'))

# 后台登录
def login():
    # 获取前端传递的json数据
    if request.method == 'GET':
        return render_template('admin/login.html')
    elif request.method == 'POST':
        username = request.form.get("username")
        password = request.form.get("password")
        _,res = common.login(username,password)
        return res


